package com.hzjy.manage.controller;

import com.hzjy.common.annotation.Log;
import com.hzjy.common.core.controller.BaseController;
import com.hzjy.common.core.domain.AjaxResult;
import com.hzjy.common.core.page.TableDataInfo;
import com.hzjy.common.enums.BusinessType;
import com.hzjy.common.utils.poi.ExcelUtil;
import com.hzjy.manage.service.impl.HzjyBannerServiceImpl;
import com.hzjy.manage.vo.HzjyBanner;
import com.hzjy.manage.vo.HzjyUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * banner图Controller
 *
 * @author hzjy
 * @date 2020-08-18
 */
@RestController
@RequestMapping("/manage/banner")
public class HzjyBannerController extends BaseController
{
    @Autowired
    private HzjyBannerServiceImpl hzjyBannerService;

    /**
     * 查询banner图列表
     */
    @PreAuthorize("@ss.hasPermi('manage:banner:list')")
    @GetMapping("/list")
    public TableDataInfo list(HzjyBanner hzjyBanner)
    {
        startPage();
        List<HzjyBanner> list = hzjyBannerService.selectHzjyBannerList(hzjyBanner);
        return getDataTable(list);
    }

    /**
     * 导出banner图列表
     */
    @PreAuthorize("@ss.hasPermi('manage:banner:export')")
    @Log(title = "banner图", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HzjyBanner hzjyBanner)
    {
        List<HzjyBanner> list = hzjyBannerService.selectHzjyBannerList(hzjyBanner);
        ExcelUtil<HzjyBanner> util = new ExcelUtil<HzjyBanner>(HzjyBanner.class);
        return util.exportExcel(list, "banner");
    }

    /**
     * 获取banner图详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:banner:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(hzjyBannerService.selectHzjyBannerById(id));
    }

    /**
     * 新增banner图
     */
    @PreAuthorize("@ss.hasPermi('manage:banner:add')")
    @Log(title = "banner图", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HzjyBanner hzjyBanner)
    {
        return toAjax(hzjyBannerService.insertHzjyBanner(hzjyBanner));
    }

    /**
     * 修改banner图
     */
    @PreAuthorize("@ss.hasPermi('manage:banner:edit')")
    @Log(title = "banner图", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HzjyBanner hzjyBanner)
    {
        return toAjax(hzjyBannerService.updateHzjyBanner(hzjyBanner));
    }

    /**
     * 删除banner图
     */
    @PreAuthorize("@ss.hasPermi('manage:banner:remove')")
    @Log(title = "banner图", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(hzjyBannerService.deleteHzjyBannerByIds(ids));
    }
    /**
     * 修改banner图的状态
     */
    /**
     * 修改banner图状态(0-不展示，1：展示中)
     */
    @PreAuthorize("@ss.hasPermi('manage:banner:edit')")
    @Log(title = "前端-用户", businessType = BusinessType.UPDATE)
    @PostMapping("/changeBannerState")
    public AjaxResult changeState(@RequestBody HzjyBanner hzjyBanner){
        return toAjax(hzjyBannerService.updateBannerState(hzjyBanner));
    }
}
